﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Service.BusinessLayer.Entities;
using Service.DataAccess.DataAccessHelper;
namespace Service.DataAccess.DataAccessLogic
{
    public class TaiKhoan_DA
    {
        public void them(TaiKhoan tk)
        {
            Helper help = new Helper();
            SqlParameter[] par = new SqlParameter[5];
            par[0] = new SqlParameter("@matk", tk.Matk);
            par[1] = new SqlParameter("@manv", tk.Manv);
            par[2] = new SqlParameter("@tendangnhap", tk.Tendangnhap);
            par[3] = new SqlParameter("@matkhau", tk.Matkhau);
            par[4] = new SqlParameter("@phanquyen", tk.Phanquyen);
            help.InsertQuery("sp_taikhoan_them", par);
        }
        public void sua(TaiKhoan tk)
        {
            Helper help = new Helper();
            SqlParameter[] par = new SqlParameter[3];
            par[0] = new SqlParameter("@tendangnhap", tk.Tendangnhap);
            par[1] = new SqlParameter("@matkhau", tk.Matkhau);
            par[2] = new SqlParameter("@phanquyen", tk.Phanquyen);
            help.UpdateQuery("sp_taikhoan_sua", par);
        }
        public void xoa(string tendangnhap)
        {
            Helper help = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@tendangnhap", tendangnhap);
            help.DeleteQuery("sp_taikhoan_xoa", par);
        }
        public DataSet LayDS()
        {
            DataSet kq = new DataSet();
            Helper help = new Helper();
            kq= help.SelectQuery("sp_taikhoan_layds");
            return kq;
        }
        public DataSet LayDS_Theo_TenDangNhap(string TenDangNhap)
        {
            Helper help = new Helper();
            DataSet ds = new DataSet();
            SqlParameter[] par = new SqlParameter[0];
            par[0] = new SqlParameter("@tendangnhap",TenDangNhap);
            ds = help.SelectQuery("sp_taikhoan_layds_tendangnhap",par);
            return ds;
        }
        public void SuaPhanQuyen(TaiKhoan tk)
        {
            Helper help = new Helper();
            SqlParameter[] par = new SqlParameter[2];
            par[0] = new SqlParameter("@tendangnhap", tk.Tendangnhap);            
            par[2] = new SqlParameter("@phanquyen", tk.Phanquyen);
            help.UpdateQuery("sp_taikhoan_suaquyen", par);
        }
        public void SuaMatKhau(TaiKhoan tk)
        {
            Helper help = new Helper();
            SqlParameter[] par = new SqlParameter[2];
            par[0] = new SqlParameter("@MaTK", tk.Matk);
            par[1] = new SqlParameter("@matkhau", tk.Matkhau);
            help.UpdateQuery("sp_taikhoan_suamatkhau", par);
        }
        public void Backup_Data(TaiKhoan tk)
        {
            Helper help = new Helper();
            SqlParameter[] par = new SqlParameter[0];
            par[0] = new SqlParameter("@filepath", tk.Duongdan);
            help.SelectQuery("BackUp_Database", par);
        }

    }
}
